package cn.uexpo.lhz.core.error;

import cn.uexpo.lhz.plus.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import static cn.uexpo.lhz.dd.RobotHelperUtil.sdkDemoJava;


/**
 * @Author 小坏
 * @Date 2020/6/18 15:39
 * @Version 1.0
 * @program: 父工程 manage 万物起源之地
 * @description: 全局捕获异常
 */
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public R exceptionHandler(Exception e) {

        log.info("###>>>>lan全局捕获异常一下信息<<<<<<<<###,error:{}", e.toString());
        StackTraceElement stackTraceElement = e.getStackTrace()[0];
        String errorMsg = ">>>>>>>文件名：" + stackTraceElement.getFileName() +
                "\r\n类名：" + stackTraceElement.getClassName() +
                "\r\n方法名：" + stackTraceElement.getMethodName() +
                "\r\n抛出异常行号：" + stackTraceElement.getLineNumber() +
                "\r\n机构ID异常，无法获取本机构信息：" + e.toString();
        sdkDemoJava(errorMsg);
        return R.ok().put("系统错误!", errorMsg);
    }
}
